<?php
declare (strict_types = 1);

namespace app\command;

use Swoole\Timer;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use Swoole\Coroutine\Http\Client;
use function Swoole\Coroutine\run;

class pullHttp extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('pullhttp')
            ->setDescription('pull http');
    }

    protected function execute(Input $input, Output $output)
    {
        Timer::tick(2000,function (){
            $cli = new Client('127.0.0.1', 80);
            $cli->setHeaders(["authorization"=>$this->getToken(),"content-type"=>"application/json"]);
            $cli->post('/index/debugData',json_encode(['a'=>1,'b'=>2]));
            echo $cli->body;
            $cli->close();
        });
        \Swoole\Event::wait();
    }

    protected function getToken()
    {
        return "12345";
    }
}
